package com.ems.controller.supers.action;

import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.permission.UserGroup;
import com.ems.service.supers.action.UserGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/5
 * @Description: 用户与角色关系类
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有ip跨域
@RequestMapping("/userGroupController")
public class UserGroupController {

    @Autowired
    @Qualifier("UserGroupService")
    private UserGroupService userGroupService;

    /**
     * 为指定的用户添加角色
     */
    @ResponseBody
    @RequestMapping("/addUserGroup")
    public ResultData addUserGroup(@RequestBody UserGroup userGroup){
        if(userGroupService.addUserGroup(userGroup) > 0){
            return RetunResult.AssemblyData();
        }
        return RetunResult.AssemblyData("failure.to.add.userGroup");
    }

    /**
     * 为指定的用户删除其对应的角色
     */
    @ResponseBody
    @RequestMapping("/deleteUserGroup")
    public ResultData deleteUserGroup(@RequestBody UserGroup userGroup){
        if(userGroupService.deleteUserGroup(userGroup) > 0){
            return RetunResult.AssemblyData();
        }
        return RetunResult.AssemblyData("failure.to.delete.userGroup");
    }

}
